package com.example.my.shop.mybatis.service.Imp;

import com.example.my.shop.mybatis.TbUser;
import com.example.my.shop.mybatis.dao.TbUserMapper;
import com.example.my.shop.mybatis.service.TbUserService;
import com.example.my.shop.mybatis.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TbUserServiceImpl implements TbUserService {
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    TbUserMapper tbUserMapper = sqlSession.getMapper(TbUserMapper.class);

    @Override
    public TbUser selectUserByEmail(String email) {
        return tbUserMapper.selectUserByEmail(email);
    }

    @Override
    public List<TbUser> findAll() {
        return tbUserMapper.findAll();
    }

    @Override
    public boolean addUser(TbUser user) {
        boolean b = tbUserMapper.addUser(user);
        sqlSession.commit();
        return b;
    }

    @Override
    public TbUser selectUserById(int id) {
        return tbUserMapper.selectUserById(id);
    }

    @Override
    public int deleteUserBuId(int id) {
        int i = tbUserMapper.deleteUserById(id);
        sqlSession.commit();
        return i;
    }

    @Override
    public int updateUser(TbUser user) {
        int i = tbUserMapper.updateTbUser(user);
        sqlSession.commit();
        return i;
    }
}
